﻿using System;

namespace PetaPoco
{
    /// <summary>
    /// Specifies whether a property should be included in SQL auto-select queries.
    /// </summary>
    public enum IncludeInAutoSelect
    {
        /// <summary>
        /// The property should not be included in auto-select queries.
        /// </summary>
        No,

        /// <summary>
        /// The property should be included in auto-select queries.
        /// </summary>
        Yes
    }

    /// <summary>
    /// The ResultColumnAttribute class defines an attribute for POCO properties that should be used in <b>SQL queries only</b>, but ignored
    /// in UPDATE and INSERT operations.
    /// </summary>
    /// <remarks>
    /// This attribute marks properties that are mapped to a column, but should not be involved in any mutating operations on the database.
    /// The property value is updated by queries from the database, but the database column it maps to will not be changed to reflect
    /// changes in this property.
    /// <para>Use the <see cref="IncludeInAutoSelect"/> property to dictate whether the decorated property is included in operations using
    /// PetaPoco's AutoSelect feature (default is <see cref="IncludeInAutoSelect.No"/>). Auto-select queries are operations made using the
    /// "short form" syntax, without specifying the <c>SELECT [cols] FROM [table]</c> portion of the SQL statement. The inferred portion of
    /// the SQL statement is then automatically generated by PetaPoco based on generics or the called method's parameters.</para>
    /// </remarks>
    [AttributeUsage(AttributeTargets.Property)]
    public class ResultColumnAttribute : ColumnAttribute
    {
        /// <summary>
        /// Gets or sets a value indicating whether the property should be included in auto-select queries.
        /// Default is <see cref="IncludeInAutoSelect.No"/>.
        /// </summary>
        public IncludeInAutoSelect IncludeInAutoSelect { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ResultColumnAttribute"/> class with default values.
        /// </summary>
        public ResultColumnAttribute()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ResultColumnAttribute"/> class with the specified column name.
        /// </summary>
        /// <param name="column">The name of the database column associated with this property.</param>
        public ResultColumnAttribute(string column)
            : this(column, IncludeInAutoSelect.No)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ResultColumnAttribute"/> class with the specified auto-select inclusion setting.
        /// </summary>
        /// <param name="includeInAutoSelect">Specifies whether the property should be included in auto-select queries.</param>
        public ResultColumnAttribute(IncludeInAutoSelect includeInAutoSelect)
            : this(null, includeInAutoSelect)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ResultColumnAttribute"/> class with the specified column name and auto-select
        /// inclusion setting.
        /// </summary>
        /// <param name="column">The name of the database column associated with this property.</param>
        /// <param name="includeInAutoSelect">Specifies whether the property should be included in auto-select queries.</param>
        public ResultColumnAttribute(string column, IncludeInAutoSelect includeInAutoSelect)
            : base(column)
        {
            IncludeInAutoSelect = includeInAutoSelect;
        }
    }
}
